package cn.chencaiju.day12;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ExecutorTest {
	public static void main(String[] args) {
		//Executor 线程执行器
		//创建具有2个线程的线程池
		ExecutorService service=Executors.newFixedThreadPool(2); 
		service.execute(new ExecutorRunnable(9));
		service.execute(new ExecutorRunnable(19));
		service.execute(new ExecutorRunnable(31));
		service.shutdown();
	}
}

class ExecutorRunnable implements Runnable{
	private int num;
	
	public ExecutorRunnable(int num) {
		super();
		this.num = num;
	}

	@Override
	public void run() {
		while(num>0) {
			try {
				Thread.sleep(1000);
				System.out.println(num--);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
}